<template lang="pug">
  .clearfix
    Modal(
      width="400"
      v-model="isShowSetSecurityTimeModal"
      title="设置参保时间"
      class-name="vertical-center-modal"
    )
      .search-form.pr-20
        Form.ivu-row(ref="formData" :model="formData" :rules="rules" :label-width="110")
          FormItem.form-item.ivu-col(v-for="(item, index) of formItem" :label="item.label" :key="index" :prop="item.prop")
            template(v-if="item.type === 'datePicker'")
              DatePicker.w-100(v-model="formData[item.model]" :placeholder="item.placeholder" type="date" format="yyyy-MM-dd")
      .clearfix(slot="footer")
        Button(type="text" @click="cancel") 取消
        Button(type="primary" @click="handleSubmit" :loading="!isCanSubmit") 确定
</template>

<script>
import { EmployeeInsuredApi } from '@/api/EmployeeInsured.api.js'

export default {
  name: '',

  props: {
  },

  data () {
    return {
      ids: null,
      securityType: null, // 商保传3，其他传0
      isShowSetSecurityTimeModal: false,
      isCanSubmit: true,
      formData: {
        insuredTime: new Date()
      },
      formItem: [
        { type: 'datePicker', label: '参保时间：', placeholder: '请选择参保时间', prop: 'insuredTime', model: 'insuredTime' },
      ],
      rules: {
        insuredTime: [
          { required: true, message: '请选择参保时间', trigger: 'select' }
        ],
      }
    }
  },

  watch: {
  },

  mounted () {
  },

  methods: {
    cancel () {
      this.isCanSubmit = true
      this.isShowSetSecurityTimeModal = false
    },

    show () {
      this.$refs.formData.resetFields()
      this.isCanSubmit = true
      this.isShowSetSecurityTimeModal = true
    },

    async handleSubmit () {
      this.isCanSubmit = false
      var params = {
        ids: this.ids.join(','),
        securityType: this.securityType,
        insuredTime: this.formData.insuredTime,
      }
      console.log('提交参保时间 params: ', params)
      let res = await EmployeeInsuredApi.batchUpateInsuredTime(params)
      console.log('设置参保时间res: ', res)
      if (res.status === 200 && res.data.success) {
        this.isShowSetSecurityTimeModal = false
        this.$Message.success(res.data.message)
        this.$emit('query')
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
        this.isCanSubmit = true
      }
    }
  }
}
</script>

<style lang="less" scope>
</style>
